package com.woniuxy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.dao.*;
import com.woniuxy.dto.DataGridView;
import com.woniuxy.pojo.MerchantUsers;
import com.woniuxy.pojo.OverOrder;
import com.woniuxy.pojo.PreOrder;
import com.woniuxy.service.OrderService;
import com.woniuxy.service.UserService;
import com.woniuxy.vo.OverOrderVo;
import com.woniuxy.vo.PreOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.math.BigDecimal;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private McarParkingMapper mcarParkingMapper;
    @Autowired
    private PreOrderMapper preOrderMapper;
    @Autowired
    private MerchantUsersMapper merchantUsersMapper;
    @Autowired
    private OverOrderMapper overOrderMapper;
    @Autowired
    private MerchantCommissionMapper merchantCommissionMapper;
    @Autowired
    private UserService userService;
    @Override
    public DataGridView findAllorders(PreOrderVo preOrderVo ) {
       MerchantUsers merchantUsers = merchantUsersMapper.findPuserByid(preOrderVo.getPid());

       preOrderVo.setPid(merchantUsers.getId());
        PageHelper pageHelper=new PageHelper();
        Page<PreOrder> page= PageHelper.startPage(preOrderVo.getPage(),preOrderVo.getLimit());
        List<PreOrder> res=preOrderMapper.findAllOreder(preOrderVo);
        return new DataGridView(page.getTotal(),res);
    }

    @Override
    public DataGridView findAlloverorders(OverOrderVo overOrderVo) {
        MerchantUsers merchantUsers = merchantUsersMapper.findPuserByid(overOrderVo.getUid());
        overOrderVo.setUid(merchantUsers.getId());
        PageHelper pageHelper=new PageHelper();
        Page<OverOrder> page= PageHelper.startPage(overOrderVo.getPage(),overOrderVo.getLimit());
        List<OverOrder> res=overOrderMapper.findAlloverorders(overOrderVo);
        return new DataGridView(page.getTotal(),res);
    }

    @Override
    public PreOrder findpreorder(String orderid) {
        return preOrderMapper.findpreorder(orderid);
    }

    @Override
    public Boolean findOverOrder(String orderid) {
       PreOrder preOrder =findpreorder(orderid);
        Integer res =overOrderMapper.findOverOrder(preOrder.getId());
        if (res>0){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public List<BigDecimal> findMerchantusersMoney(Integer id) {
      MerchantUsers merchantUsers=  userService.findPuserByid(id);
        return merchantCommissionMapper.findMerchantusersMoney(merchantUsers.getId());
    }
}
